﻿using CJAtech.BBS.Business;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TjZheng.Quartz;
using TjZheng.Framework;
using System.Data;
using CJAtech.BBS.DataEntity;
using TjZheng.Base;

namespace TjZheng.SyncBBSRedis
{
    public class SyncChuanQiArticle : TjZhengJob
    {
        public override void JobExecute(global::Quartz.IJobExecutionContext context)
        {
            BizArticleInfo objBizArticleInfo = new BizArticleInfo("CJAtech.BBS.ConnectionString", "");
            BizArticleInfoData objBizArticleInfoData = new BizArticleInfoData("CJAtech.BBS.ConnectionString", "");
            ArticleInfoData objArticleInfoData = null;
            List<ArticleInfoData> objArticleInfoDataList = null;
            DataTable objDataTable = null;
            int pageIndex = 0;
            ConsoleHelper.WriteLineYellow("【同步传奇文章数据】开始同步……");
            while (true)
            {
                objDataTable = objBizArticleInfo.DbHelper.ExecuteDataTable("BBS_ArticleInfo_TB", pageIndex, 20, "", "", "ArticleId,ArticleContent", "ArticleId");
                if (objDataTable.IsNull())
                {
                    ConsoleHelper.WriteLineYellow("【同步传奇文章数据】第" + (pageIndex + 1) + "页数据没有数据，同步结束");
                    break;
                }
                ConsoleHelper.WriteLineYellow("【同步传奇文章数据】开始同步第" + (pageIndex + 1) + "页数据");
                objArticleInfoDataList = new List<ArticleInfoData>();
                foreach (DataRow objDataRow in objDataTable.Rows)
                {
                    objArticleInfoData = new ArticleInfoData();
                    objArticleInfoData.ArticleId = objDataRow["ArticleId"].ConvertTarget<int>();
                    objArticleInfoData.ArticleContent = objDataRow["ArticleContent"].ConvertTarget<string>();
                    objArticleInfoData.InfoDataType = ArticleInfoDataType.ArticleContent;
                    objArticleInfoDataList.Add(objArticleInfoData);
                    objArticleInfoData.SetState(EntityStatus.Added);
                }
                objBizArticleInfoData.Batch(objArticleInfoDataList);
                ConsoleHelper.WriteLineYellow("【同步传奇文章数据】第" + (pageIndex + 1) + "页数据同步成功");
                pageIndex++;
            }
        }
    }
}
